.class public final Lcom/baidu/crabsdk/sender/a;
.super Ljava/lang/Object;


# instance fields
.field private bs:Landroid/app/ActivityManager;

.field private bt:I

.field private mContext:Landroid/content/Context;


# direct methods
.method public constructor <init>(Landroid/content/Context;)V
    .locals 1

    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    const/4 v0, 0x0

    iput-object v0, p0, Lcom/baidu/crabsdk/sender/a;->bs:Landroid/app/ActivityManager;

    iput-object v0, p0, Lcom/baidu/crabsdk/sender/a;->mContext:Landroid/content/Context;

    const/16 v0, -0x64

    iput v0, p0, Lcom/baidu/crabsdk/sender/a;->bt:I

    iput-object p1, p0, Lcom/baidu/crabsdk/sender/a;->mContext:Landroid/content/Context;

    const-string v0, "activity"

    invoke-virtual {p1, v0}, Landroid/content/Context;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;

    move-result-object p1

    check-cast p1, Landroid/app/ActivityManager;

    iput-object p1, p0, Lcom/baidu/crabsdk/sender/a;->bs:Landroid/app/ActivityManager;

    return-void
.end method

.method private R()Landroid/app/ActivityManager$ProcessErrorStateInfo;
    .locals 4

    :try_start_0
    iget-object v0, p0, Lcom/baidu/crabsdk/sender/a;->bs:Landroid/app/ActivityManager;

    invoke-virtual {v0}, Landroid/app/ActivityManager;->getProcessesInErrorState()Ljava/util/List;

    move-result-object v0

    if-eqz v0, :cond_1

    invoke-interface {v0}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v0

    :cond_0
    invoke-interface {v0}, Ljava/util/Iterator;->hasNext()Z

    move-result v1

    if-eqz v1, :cond_1

    invoke-interface {v0}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Landroid/app/ActivityManager$ProcessErrorStateInfo;

    iget v2, v1, Landroid/app/ActivityManager$ProcessErrorStateInfo;->condition:I
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    const/4 v3, 0x2

    if-ne v2, v3, :cond_0

    return-object v1

    :catch_0
    move-exception v0

    const-string v1, "getProcessErrorStateInfo error!"

    invoke-static {v1, v0}, Lcom/baidu/crabsdk/c/a;->a(Ljava/lang/String;Ljava/lang/Throwable;)I

    :cond_1
    const/4 v0, 0x0

    return-object v0
.end method

.method private static a(Landroid/app/ActivityManager$ProcessErrorStateInfo;Ljava/lang/String;)Ljava/util/Map;
    .locals 8
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Landroid/app/ActivityManager$ProcessErrorStateInfo;",
            "Ljava/lang/String;",
            ")",
            "Ljava/util/Map<",
            "Ljava/lang/String;",
            "Ljava/lang/Object;",
            ">;"
        }
    .end annotation

    const-string v0, "("

    const-string v1, "ANR"

    new-instance v2, Ljava/util/HashMap;

    invoke-direct {v2}, Ljava/util/HashMap;-><init>()V

    const/4 v3, 0x0

    :try_start_0
    invoke-static {}, Landroid/os/Looper;->getMainLooper()Landroid/os/Looper;

    move-result-object v4

    invoke-virtual {v4}, Landroid/os/Looper;->getThread()Ljava/lang/Thread;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/Thread;->getStackTrace()[Ljava/lang/StackTraceElement;

    move-result-object v4

    if-eqz v4, :cond_1

    array-length v5, v4

    if-lez v5, :cond_1

    new-instance v5, Ljava/lang/StringBuilder;

    invoke-direct {v5}, Ljava/lang/StringBuilder;-><init>()V

    const/4 v6, 0x0

    :goto_0
    array-length v7, v4

    if-ge v6, v7, :cond_0

    aget-object v7, v4, v6

    invoke-virtual {v7}, Ljava/lang/StackTraceElement;->toString()Ljava/lang/String;

    move-result-object v7

    invoke-virtual {v5, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    const-string v7, "\n"

    invoke-virtual {v5, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    add-int/lit8 v6, v6, 0x1

    goto :goto_0

    :cond_0
    const-string v6, "mainThread"

    invoke-virtual {v5}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v5

    invoke-interface {v2, v6, v5}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    :cond_1
    const-string v5, "apiType"

    invoke-interface {v2, v5, v1}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    const-string v5, "errorType"

    invoke-interface {v2, v5, v1}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    const-string v1, ""

    iget-object v5, p0, Landroid/app/ActivityManager$ProcessErrorStateInfo;->shortMsg:Ljava/lang/String;

    if-eqz v5, :cond_2

    iget-object v5, p0, Landroid/app/ActivityManager$ProcessErrorStateInfo;->shortMsg:Ljava/lang/String;

    invoke-virtual {v5, v0}, Ljava/lang/String;->contains(Ljava/lang/CharSequence;)Z

    move-result v5

    if-eqz v5, :cond_2

    iget-object v1, p0, Landroid/app/ActivityManager$ProcessErrorStateInfo;->shortMsg:Ljava/lang/String;

    iget-object v5, p0, Landroid/app/ActivityManager$ProcessErrorStateInfo;->shortMsg:Ljava/lang/String;

    invoke-virtual {v5, v0}, Ljava/lang/String;->indexOf(Ljava/lang/String;)I

    move-result v0

    invoke-virtual {v1, v3, v0}, Ljava/lang/String;->substring(II)Ljava/lang/String;

    move-result-object v1

    :cond_2
    const-string v0, "type"

    invoke-interface {v2, v0, v1}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    const-string v0, "anrMsg"

    iget-object v1, p0, Landroid/app/ActivityManager$ProcessErrorStateInfo;->longMsg:Ljava/lang/String;

    invoke-interface {v2, v0, v1}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    const-string v0, "processId"

    iget v1, p0, Landroid/app/ActivityManager$ProcessErrorStateInfo;->pid:I

    invoke-static {v1}, Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;

    move-result-object v1

    invoke-interface {v2, v0, v1}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    const-string v0, "processName"

    iget-object p0, p0, Landroid/app/ActivityManager$ProcessErrorStateInfo;->processName:Ljava/lang/String;

    invoke-interface {v2, v0, p0}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    const-string p0, "time"

    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v0

    invoke-static {v0, v1}, Ljava/lang/Long;->valueOf(J)Ljava/lang/Long;

    move-result-object v0

    invoke-interface {v2, p0, v0}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    const-string p0, "threadList"

    invoke-static {}, Lcom/baidu/crabsdk/b/r;->L()Ljava/lang/String;

    move-result-object v0

    invoke-interface {v2, p0, v0}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    if-eqz v4, :cond_3

    array-length p0, v4

    if-lez p0, :cond_3

    const-string p0, "errorLine"

    aget-object v0, v4, v3

    invoke-virtual {v0}, Ljava/lang/StackTraceElement;->toString()Ljava/lang/String;

    move-result-object v0

    invoke-interface {v2, p0, v0}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    const-string p0, "errorOriLine"

    aget-object v0, v4, v3

    invoke-virtual {v0}, Ljava/lang/StackTraceElement;->toString()Ljava/lang/String;

    move-result-object v0

    invoke-interface {v2, p0, v0}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_1

    :catch_0
    move-exception p0

    const-string v0, "\u5c01\u88c5anr\u6570\u636e\u5931\u8d25!"

    invoke-static {v0, p0}, Lcom/baidu/crabsdk/c/a;->a(Ljava/lang/String;Ljava/lang/Throwable;)I

    :cond_3
    :goto_1
    :try_start_1
    invoke-static {p1}, Lcom/baidu/crabsdk/sender/g;->o(Ljava/lang/String;)[B

    move-result-object p0

    if-eqz p0, :cond_4

    array-length p1, p0

    if-lez p1, :cond_4

    invoke-static {p0, v3}, Landroid/util/Base64;->encodeToString([BI)Ljava/lang/String;

    move-result-object p0

    const-string p1, "trace"

    invoke-interface {v2, p1, p0}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    goto :goto_2

    :cond_4
    const-string p0, "read trace file error!"

    invoke-static {p0}, Lcom/baidu/crabsdk/c/a;->v(Ljava/lang/String;)I
    :try_end_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_2
    .catch Ljava/lang/OutOfMemoryError; {:try_start_1 .. :try_end_1} :catch_1

    goto :goto_2

    :catch_1
    move-exception p0

    invoke-virtual {p0}, Ljava/lang/OutOfMemoryError;->getMessage()Ljava/lang/String;

    move-result-object p0

    invoke-static {p0}, Lcom/baidu/crabsdk/c/a;->v(Ljava/lang/String;)I

    goto :goto_2

    :catch_2
    move-exception p0

    const-string p1, "wrap trace to anrRecord error!"

    invoke-static {p1, p0}, Lcom/baidu/crabsdk/c/a;->a(Ljava/lang/String;Ljava/lang/Throwable;)I

    :goto_2
    return-object v2
.end method

.method private e(Ljava/lang/String;)Z
    .locals 5

    const/4 v0, 0x1

    :try_start_0
    invoke-direct {p0}, Lcom/baidu/crabsdk/sender/a;->R()Landroid/app/ActivityManager$ProcessErrorStateInfo;

    move-result-object v1

    const/4 v2, 0x0

    if-nez v1, :cond_0

    return v2

    :cond_0
    iget v3, v1, Landroid/app/ActivityManager$ProcessErrorStateInfo;->pid:I

    invoke-static {}, Landroid/os/Process;->myPid()I

    move-result v4

    if-ne v3, v4, :cond_3

    const-string v3, "anr info catched..."

    invoke-static {v3}, Lcom/baidu/crabsdk/c/a;->s(Ljava/lang/String;)I

    iget-object v3, p0, Lcom/baidu/crabsdk/sender/a;->mContext:Landroid/content/Context;

    const/4 v4, 0x0

    invoke-static {v3, v4, v2}, Lcom/baidu/crabsdk/sender/e;->a(Landroid/content/Context;Ljava/lang/Throwable;Z)Ljava/util/Map;

    move-result-object v3

    invoke-static {v1, p1}, Lcom/baidu/crabsdk/sender/a;->a(Landroid/app/ActivityManager$ProcessErrorStateInfo;Ljava/lang/String;)Ljava/util/Map;

    move-result-object p1

    if-nez v3, :cond_1

    const-string p1, "info map is null!"

    invoke-static {p1}, Lcom/baidu/crabsdk/c/a;->w(Ljava/lang/String;)I

    return v0

    :cond_1
    invoke-interface {v3, p1}, Ljava/util/Map;->putAll(Ljava/util/Map;)V

    invoke-static {v3}, Lcom/baidu/crabsdk/sender/e;->a(Ljava/util/Map;)V

    invoke-static {v3}, Lcom/baidu/crabsdk/sender/g;->c(Ljava/util/Map;)Ljava/lang/String;

    move-result-object v1

    iget-object v3, p0, Lcom/baidu/crabsdk/sender/a;->mContext:Landroid/content/Context;

    invoke-static {v3, v1}, Lcom/baidu/crabsdk/sender/g;->a(Landroid/content/Context;Ljava/lang/String;)V

    invoke-static {}, Lcom/baidu/crabsdk/sender/f;->ab()V

    invoke-static {}, Lcom/baidu/crabsdk/sender/f;->U()Z

    move-result v1

    if-eqz v1, :cond_2

    const-string v1, "begin to upload anr info..."

    invoke-static {v1}, Lcom/baidu/crabsdk/c/a;->s(Ljava/lang/String;)I

    iget-object v1, p0, Lcom/baidu/crabsdk/sender/a;->mContext:Landroid/content/Context;

    invoke-static {v2, v1}, Lcom/baidu/crabsdk/sender/i;->a(ZLandroid/content/Context;)V

    :cond_2
    sget-object v1, Lcom/baidu/crabsdk/a;->N:Lcom/baidu/crabsdk/OnAnrCrashListener;

    if-eqz v1, :cond_4

    sget-object v1, Lcom/baidu/crabsdk/a;->N:Lcom/baidu/crabsdk/OnAnrCrashListener;

    invoke-interface {v1, p1}, Lcom/baidu/crabsdk/OnAnrCrashListener;->onAnrStarted(Ljava/util/Map;)V

    goto :goto_0

    :cond_3
    new-instance p1, Ljava/lang/StringBuilder;

    const-string v1, "Anr occur! But not the current pid!"

    invoke-direct {p1, v1}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-static {}, Landroid/os/Process;->myPid()I

    move-result v1

    invoke-virtual {p1, v1}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    invoke-virtual {p1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object p1

    invoke-static {p1}, Lcom/baidu/crabsdk/c/a;->s(Ljava/lang/String;)I

    :cond_4
    :goto_0
    const-string p1, "getLogcatErrorInfo return true"

    invoke-static {p1}, Lcom/baidu/crabsdk/c/a;->s(Ljava/lang/String;)I
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_1
    .catch Ljava/lang/OutOfMemoryError; {:try_start_0 .. :try_end_0} :catch_0

    return v0

    :catch_0
    move-exception p1

    invoke-virtual {p1}, Ljava/lang/OutOfMemoryError;->getMessage()Ljava/lang/String;

    move-result-object p1

    invoke-static {p1}, Lcom/baidu/crabsdk/c/a;->v(Ljava/lang/String;)I

    return v0

    :catch_1
    move-exception p1

    const-string v1, "getLogcatErrorInfo error!"

    invoke-static {v1, p1}, Lcom/baidu/crabsdk/c/a;->a(Ljava/lang/String;Ljava/lang/Throwable;)I

    return v0
.end method


# virtual methods
.method public final d(Ljava/lang/String;)V
    .locals 8

    iget v0, p0, Lcom/baidu/crabsdk/sender/a;->bt:I

    invoke-static {}, Landroid/os/Process;->myPid()I

    move-result v1

    if-eq v0, v1, :cond_2

    invoke-static {}, Landroid/os/Process;->myPid()I

    move-result v0

    iput v0, p0, Lcom/baidu/crabsdk/sender/a;->bt:I

    :try_start_0
    const-string v0, "anr trace logic thread."

    invoke-static {v0}, Lcom/baidu/crabsdk/c/a;->s(Ljava/lang/String;)I

    invoke-direct {p0, p1}, Lcom/baidu/crabsdk/sender/a;->e(Ljava/lang/String;)Z

    move-result v0

    invoke-static {}, Ljava/lang/System;->nanoTime()J

    move-result-wide v1
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_1

    :cond_0
    if-nez v0, :cond_1

    const-wide/16 v3, 0x32

    :try_start_1
    invoke-static {v3, v4}, Ljava/lang/Thread;->sleep(J)V
    :try_end_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_0

    goto :goto_0

    :catch_0
    move-exception v0

    :try_start_2
    invoke-virtual {v0}, Ljava/lang/Exception;->printStackTrace()V

    :goto_0
    invoke-direct {p0, p1}, Lcom/baidu/crabsdk/sender/a;->e(Ljava/lang/String;)Z

    move-result v0

    invoke-static {}, Ljava/lang/System;->nanoTime()J

    move-result-wide v3

    sub-long/2addr v3, v1

    const-wide/32 v5, 0xf4240

    div-long/2addr v3, v5

    const-wide/16 v5, 0x7530

    cmp-long v7, v3, v5

    if-lez v7, :cond_0

    const-string p1, "anr trace logic timeout!"

    invoke-static {p1}, Lcom/baidu/crabsdk/c/a;->w(Ljava/lang/String;)I
    :try_end_2
    .catch Ljava/lang/Exception; {:try_start_2 .. :try_end_2} :catch_1

    :cond_1
    return-void

    :catch_1
    move-exception p1

    const-string v0, "processErrorStateInfo error!"

    invoke-static {v0, p1}, Lcom/baidu/crabsdk/c/a;->a(Ljava/lang/String;Ljava/lang/Throwable;)I

    :cond_2
    return-void
.end method
